/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
private class HelloWorldTestClass {

    static testMethod void myUnitTest() {
        // TO DO: implement unit test
        // Will always pass the test
        System.assert( true);
    }
    
	//TODO: Create a test method
	public static testMethod void myHelloWorldTester() {

		List<Position__c> positions = new List<Position__c>();
		for (Integer i=0; i < 20; i++){
			Position__c p = new Position__c();
			p.Name = 'testName' + i;
			p.Job_Description__c = 'testDescription' + i;
			positions.add(p);
		}
		
		//TODO: Wrap the following section in a try block
		try {

			System.debug('Attempting to insert positions');
			//TODO: Insert Positions
			insert positions;
			System.debug('Insert complete');

			// refresh the Position list to include the Hello__c field after the insert
			
			
			//TODO: Create a position map to hold position IDs
			Map<ID,Position__c> positionMap = new Map<ID,Position__c>(positions);


			//TODO: Write a SOQL statement to retrieve id, name and Hello_c into positions based on the IDs in the position map
			positions = [select id, name, Hello__c from Position__c where id in :positionMap.keySet()];
			

			//TODO: Write a loop to iterate through the positions object
			for ( Position__c pos : positions) {
			//TODO: Inside the loop: ensure position id is not null and hello field contains 'World'
				System.assertNotEquals(pos.id,null);
				System.assertEquals(pos.Hello__c, 'World');
				System.debug('position.id=' + pos.id);
				System.debug('position.name=' + pos.name);
				System.debug('position.Hello__c=' + pos.Hello__c);				
			}
		} catch ( DMLException dmle) {
			//TODO: Wrap the following section in a catch block
			System.debug('We caught a DML exception: ' + dmle.getDmlMessage(0));	
		} catch ( Exception e) {
			System.debug( 'Exception caught during test method HelloWorldTestClass.myHelloWorldTester(): ' + e.getMessage());
		}
			

		
	}
}